<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>网站后台管理</title>
<link rel="stylesheet" type="text/css"
	href="./static/layui/css/layui.css" />
<link rel="stylesheet" type="text/css" href="./static/css/admin.css" />
<script src="./js/jquery-2.0.3.js" type="text/javascript"
	charset="utf-8"></script>

</head>
<body>
	<div class="layui-tab page-content-wrap">
		<ul class="layui-tab-title">
			<li class="layui-this">修改资料</li>
			<li>修改密码</li>
		</ul>
		<div class="layui-tab-content">
			<div class="layui-tab-item layui-show">


				<form class="layui-form" style="width: 90%; padding-top: 20px;">
					<div class="layui-form-item">
						<label class="layui-form-label">工号</label>
						<div class="layui-input-block">
							<input type="text" name="empno" id="empno" lay-verify="title"
								autocomplete="off" class="layui-input layui-disabled"
								required="required" readonly value="${emp2.empno}">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">姓名</label>
						<div class="layui-input-block">
							<input type="text" name="empname" id="empname" lay-verify="title"
								autocomplete="off" class="layui-input layui-disabled"
								required="required" readonly value="${emp2.empname}">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">电话</label>
						<div class="layui-input-block">
							<input type="text" name="empphone" id="empphone"
								lay-verify="title" autocomplete="off" value="${emp2.empphone}"
								pattern="[0-9]{11}" class="layui-input" required="required">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">邮箱</label>
						<div class="layui-input-block">
							<input type="email" name="empemail" id="empemail"
								lay-verify="title" autocomplete="off" value="${emp2.empemail}"
								class="layui-input" required="required">
						</div>
					</div>
					<div class="layui-form-item" id="area-picker">


						<div class="layui-form-label">地址</div>
						<div class="layui-input-inline" style="width: 200px;">
							<select name="province" id="province" class="province-selector"
								lay-filter="province-1">
								<option value="">请选择省</option>
							</select>
						</div>
						<div class="layui-input-inline" style="width: 200px;">
							<select name="city" id="city" class="city-selector" lay-filter="city-1">
								<option value="">请选择市</option>
							</select>
						</div>
						<div class="layui-input-inline" style="width: 200px;">
							<select name="county" id="county" class="county-selector"
								lay-filter="county-1">
								<option value="">请选择区</option>
							</select>
						</div>

					</div>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn layui-btn-normal" lay-submit
								lay-filter="adminInfo">立即提交</button>
						</div>
					</div>
				</form>
			</div>
			
			<!-- 修改密码 -->
			<div class="layui-tab-item">
				<form class="layui-form" style="width: 90%; padding-top: 20px;">
					<div class="layui-form-item">
						<label class="layui-form-label">工号：</label>
						<div class="layui-input-block">
							<input type="text" name="empno" id="empno" disabled autocomplete="off"
								class="layui-input layui-disabled" value="${emp2.empno}">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">旧密码：</label>
						<div class="layui-input-block">
							<input type="password" name="emppwd" id="emppwd" required
								lay-verify="required" placeholder="请输入密码" autocomplete="off"
								class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">新密码：</label>
						<div class="layui-input-block">
							<input type="password" name="password" id="password" required
								lay-verify="required" placeholder="请输入密码" autocomplete="off"
								class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">重复密码：</label>
						<div class="layui-input-block">
							<input type="password" name="password1" id="password1" required
								lay-verify="required" placeholder="请输入密码" autocomplete="off"
								class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn layui-btn-normal" lay-submit
								lay-filter="adminPassword">立即提交</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
	<script src="./layui/layui.js" type="text/javascript" charset="utf-8"></script>

	<script>
		//配置插件目录
		layui.config({
			base : './mods/',
			version : '1.0'
		});
		//Demo
		layui.use([ 'form', 'element', 'layer', 'layarea' ], function() {
			var form = layui.form;
			var element = layui.element;
			var layer = layui.layer;
			var layarea = layui.layarea;
			form.render();
			layarea.render({
				elem : '#area-picker',
				change : function(res) {
					//选择结果
					console.log(res);
				}
			});
			//监听 个人资料修改  提交
			form.on('submit(adminInfo)', function(data) {
				var empno = $("#empno").val();
				var empphone = $("#empphone").val();
				var empemail = $("#empemail").val();
				
				var province = document.getElementById('province');
				var aid = province.selectedIndex;
				var city = document.getElementById('city');
				var bid = city.selectedIndex;
				var county = document.getElementById('county');
				var cid = county.selectedIndex;
				//alert(province[aid].value+'-'+city[bid].value+'-'+county[cid].value);
				

				var empaddress = province[aid].value+'-'+city[bid].value+'-'+county[cid].value ;
				console.log(province);
				console.log(city);
				console.log(county);
				console.log(empaddress);
				//console.log(empphone);
				if (!(/^1[3456789]\d{9}$/.test(empphone))) {
					layer.msg("手机号码有误，请重填");
					return false;
				}
				$.ajax({
					type : "put", //提交方式
					url : "updateSQL", ////地址和springmvc中控制器地址一致
					data : JSON.stringify({
						"empphone" : empphone,
						"empemail" : empemail,
						"empaddress" : empaddress,
						"empno": empno
					}), //提交给控制器的数据
					contentType : "application/json", //提交给控制的数据 格式
					success : function(flag) {
						console.log(flag);
						layer.msg(flag == true ? "信息修改成功"
								: "信息修改失败", {
							time : 2000
						//两秒延迟
						}, function() {
							if (flag == true) {

								//obj.update(); ?? 理想
								//layer.close(index);
								parent.layer.closeAll();//关闭所有,简单粗暴
								window.parent.location.reload();//刷新父页面
							}

						});

					}
				});

				return false;

			});
			//监听 修改密码  提交
			form.on('submit(adminPassword)', function(data) {
				var empno = $("#empno").val();
				var emppwd = $("#emppwd").val();
				var password = $("#password").val();
				var password1 = $("#password1").val();
				console.log("empno:"+empno);
				console.log(emppwd);
				console.log(password);
				console.log(password1);
				var pwd = ${emp2.emppwd};
				console.log("pwd:"+pwd);
				
				
				if (emppwd != pwd) {
					layer.msg("旧密码错误！请重新填写！");
					return false;
				}
				if (password != password1) {
					layer.msg("两次填写的新密码不一致，请重新填写！");
					return false;
				}
				$.ajax({
					type : "put", //提交方式
					url : "updateSQL", ////地址和springmvc中控制器地址一致
					data : JSON.stringify({
						"emppwd" : password1,
						"empno": empno
					}), //提交给控制器的数据
					contentType : "application/json", //提交给控制的数据 格式
					success : function(flag) {
						console.log(flag);
						layer.msg(flag == true ? "密码修改成功,请重新登录！"
								: "密码修改失败", {
							time : 2000
						//两秒延迟
						}, function() {
							if (flag == true) {

								//obj.update(); ?? 理想
								//layer.close(index);
								parent.layer.closeAll();//关闭所有,简单粗暴
								window.parent.location.reload();//刷新父页面
							}

						});

					}
				});
				
				
				
				return false;
			});
		});
	</script>
</body>
</html>